#!/bin/bash

echo running $0 >&2

# first parameter is the output file
# take input from stdin....

outf=$1

tmp=tmp-$$

awk 'BEGIN{
	print "\\documentclass{report}"
	print "\\usepackage[landscape]{geometry}"	
	print "\\usepackage{amsmath}"
	print "\\usepackage{color}"
	print "\\begin{document}"
	print "\\pagestyle{empty}"
#	print "\\fontsize{107}{134}\\selectfont"
	print "\\Huge\\noindent"
}
{print}
END{print "\\end{document}"}'| (latex && dvips -E -D6000 -p 1 -l 1 texput.dvi -o $tmp.ps) > /dev/null 2>&1

if [[ -f $tmp.ps ]]; then
	if [[ ! -z $(echo $outf|awk '/\.pdf$/{print "pdf"}') ]]; then
		epstopdf $tmp.ps -o $outf >&2
	else
		convert $tmp.ps $outf >&2
	fi
else
	echo error compiling latex
	cp texput.log $outf.log
fi

rm -f texput.* $tmp.* missfont.log

# on failure -> do not produce any file 
